package com.onepower.admin.authorization;

import com.onepower.core.utils.JsonUtil;
import com.onepower.core.utils.SecurityUtil;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.Map;

/**
 * @author lixiaofeng
 * @date 2019/12/31 15:37
 */
@Component
@Getter
public class TokenHelper {

    @Value("${jwt.signing-key}")
    private String SIGNING_KEY;

    @Value("${jwt.auth-header}")
    private String AUTH_HEADER;

    @Value("${jwt.expiration-time}")
    private long EXPIRATION_TIME;

    public String getToken(HttpServletRequest httpServletRequest){
        String token = httpServletRequest.getHeader(AUTH_HEADER);
        return token;
    }



    public Map<String,Object> getDecryptString( String token ){
        try {
            String tokenStr = SecurityUtil.getDecryptString(token,"tkdMatch");
            Map<String,Object> userMap = JsonUtil.getInstance().json2Object(tokenStr, Map.class);
            return userMap;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }


}
